﻿Public Class Form1
    Dim ScreenNow As Integer = My.Computer.Screen.WorkingArea.Height
    Dim MouseNow As Integer = MousePosition.Y
    Dim MouseNext As Integer = MousePosition.Y
    Dim ScreenSize As Integer = My.Computer.Screen.Bounds.Height
    Dim inactivity As Integer = 0
    Dim power As PowerStatus = SystemInformation.PowerStatus

    Dim xMouse
    Dim yMouse
    Dim oldX = 0
    Dim oldY = 0

    Private Sub ALL_Tick(sender As Object, e As EventArgs) Handles All.Tick
        Label1.Text = TimeOfDay.Hour & ":" & TimeOfDay.Minute
        Label2.Text = Date.Today.ToLongDateString
        Select Case power.BatteryChargeStatus
            Case BatteryChargeStatus.Charging Or BatteryChargeStatus.High
                PictureBox1.Image = My.Resources.Battery
            Case BatteryChargeStatus.Charging Or BatteryChargeStatus.Low
                PictureBox1.Image = My.Resources.Battery
            Case BatteryChargeStatus.Charging Or BatteryChargeStatus.Critical
                PictureBox1.Image = My.Resources.Battery




            Case BatteryChargeStatus.High
                PictureBox1.Image = My.Resources.Battery_100

            Case BatteryChargeStatus.Low
                PictureBox1.Image = My.Resources.Battery_30

            Case BatteryChargeStatus.Critical
                PictureBox1.Image = My.Resources.Battery_20
        End Select
    End Sub

    Private Sub Form1_GotFocus(sender As Object, e As EventArgs) Handles Me.GotFocus
        TopMostTimer.Start()
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If My.Settings.Back = "" Then
            Me.BackgroundImage = My.Resources.LOCK
        Else
            Me.BackgroundImage = Image.FromFile(My.Settings.Back)
        End If
        Me.Location = New Point(0, 0)
        Me.Width = My.Computer.Screen.WorkingArea.Width
        Me.Height = (My.Computer.Screen.WorkingArea.Height + 45)

        If My.Computer.Network.IsAvailable = True Then
            pic_connection.Image = My.Resources.wifi_yes
        Else
            pic_connection.Image = My.Resources.wifi_no
        End If
    End Sub

    Private Sub TopMostTimer_Tick(sender As Object, e As EventArgs) Handles TopMostTimer.Tick
        Me.TopMost = True
        Me.Focus()
    End Sub

    Private Sub ShowPLayer_Click(sender As Object, e As EventArgs) Handles ShowPLayer.Click
        UserControl11.Visible = True
        TopMostTimer.Stop()
    End Sub

    Private Sub HIdePlayerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HIdePlayerToolStripMenuItem.Click
        UserControl11.Visible = False
    End Sub

    Private Sub UP_Tick(sender As Object, e As EventArgs) Handles UP.Tick
        If Me.Location.Y < ScreenSize - 2 Then
            Me.Location = New Point(0, Me.Location.Y - 40)
            If Me.Location.Y <= ScreenSize - (ScreenSize * 2) Then                
                UP.Stop()
            End If
        End If
    End Sub

    Private Sub Panel1_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel1.MouseDown
        MouseNow = MousePosition.Y
        UPMOUSE.Start()
    End Sub

    Private Sub UPMOUSE_Tick(sender As Object, e As EventArgs) Handles UPMOUSE.Tick
        MouseNext = MousePosition.Y
        If MouseNow > MouseNext Then
            MouseNext = MouseNext - MouseNow
            Me.Location = New Point(0, MouseNext)
        End If
    End Sub

    Private Sub Panel1_MouseUp(sender As Object, e As MouseEventArgs) Handles Panel1.MouseUp
        UPMOUSE.Stop()
        If MousePosition.Y < ScreenSize - 2 Then
            UP.Start()
        End If
    End Sub
    Private Sub Down_Tick(sender As Object, e As EventArgs) Handles Down.Tick
        Dim ScreenSize As Integer = My.Computer.Screen.WorkingArea.Height
        Me.Location = New Point(0, Me.Location.Y - 30)
        If Me.Location.Y = 0 Then
            Down.Stop()
        End If
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        xMouse = MousePosition.X
        yMouse = MousePosition.Y
        If xMouse = oldX And yMouse = oldY Then
            inactivity = inactivity + 1
            If inactivity = My.Settings.INACTIV Then
                Me.Location = New Point(0, 0)
                TopMostTimer.Start()
                inactivity = 0
                If My.Settings.HIBER = "TRUE" Then
                    Application.SetSuspendState(PowerState.Hibernate, True, True)
                End If
                If My.Settings.SLEEP = "TRUE" Then
                    Application.SetSuspendState(PowerState.Suspend, True, True)
                End If
            End If
        End If
        oldX = xMouse
        oldY = yMouse
    End Sub

    Private Sub CloseToolStripMenuItem_Click(sender As Object, e As EventArgs)
        Me.Close()
    End Sub

    Private Sub AltToolStripMenuItem_Click(sender As Object, e As EventArgs)
        UP.Start()
    End Sub

    Private Sub connection_Tick(sender As Object, e As EventArgs) Handles connection.Tick
        If My.Computer.Network.IsAvailable = True Then
            pic_connection.Image = My.Resources.wifi_yes
        Else
            pic_connection.Image = My.Resources.wifi_no
        End If
    End Sub

    Private Sub btn_settings_Click(sender As Object, e As EventArgs) Handles btn_settings.Click
        Me.Location = New Point(Me.Location.X, Me.Location.Y - 2)
        UP.Start()
        TopMostTimer.Stop()
        Settings.Show()
    End Sub

    Private Sub CtrllToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CtrllToolStripMenuItem.Click
        Me.Location = New Point(0, 0)
        TopMostTimer.Start()
    End Sub

    Private Sub EnterToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EnterToolStripMenuItem.Click
        Me.Location = New Point(Me.Location.X, Me.Location.Y - 2)
        UP.Start()
    End Sub

    Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
        Me.Close()
    End Sub
End Class
